package com.itheima.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * @author yunfei
 * @date 2022年10月22日 16:50
 */
@Component
@Slf4j
public class KafkaListenerDemo {


    /*@KafkaListener(topics = "topicA", containerFactory = "manualListenerContainerFactory")
    public void listen(List<ConsumerRecord<String, String>> records, Acknowledgment ack) {
        try {
            //解析消息
            log.info("kafka成功，当前成功的批次。data:{}", records);
            for (ConsumerRecord record : records) {
                //处理消息
                log.info("处理消息 : {}", record);
            }
            //手动提交 至关重要
            ack.acknowledge();
        } catch (Exception e) {
            log.error("kafka失败，当前失败的批次。data:{}", records);
            e.printStackTrace();
            ack.nack(500);
        }
    }*/

    //@KafkaListener(topics = "topicA")
    @KafkaListener(topics = "itcast-topic-out")
    public void listen(String msg) {
        System.out.println("msg = " + msg);
    }

}